package com.loli;

import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.text.method.ScrollingMovementMethod;
import android.widget.ImageView;
import android.widget.TextView;

import com.constants.Constants;
import com.model.HttpResponseObject;
import com.utils.HttpUtils;

public class ImgDetailActivity extends Activity {

	private TextView titleView;
	private ImageView imgsView;
	private TextView detailInfoView;
	
	HandlerThread handlerThread;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.img_detail);
		handlerThread = new HandlerThread("ImgDetailHandlerThread");
		Intent intent = getIntent();
		Bundle bundle = intent.getExtras();
		String infoId = bundle.getString("infoId");
		HttpResponseObject httpResponseObject = HttpUtils
				.getInfoFromUrl(Constants.USER_DETAIL_URL + "infoId=" + infoId);
		Map<String, Object> map = httpResponseObject.getHttpResponseObject();
		String title = (String) map.get("title");
		String info = (String) map.get("info");
		String imgs = (String) map.get("imgs");
		titleView = (TextView) findViewById(R.id.title);
		imgsView = (ImageView) findViewById(R.id.imgs);
		detailInfoView = (TextView) findViewById(R.id.detailInfo);
		detailInfoView.setMovementMethod(ScrollingMovementMethod.getInstance()); // 滚动条
		titleView.setText(title);
		detailInfoView.setText(info);
		Handler handler = new Handler();
		BitmapThread bitmapThread = new BitmapThread(imgs, imgsView);
		handler.post(bitmapThread);
	}

	class BitmapThread implements Runnable {

		private String url;
		private ImageView iv;

		public BitmapThread() {

		}

		public BitmapThread(String url, ImageView iv) {
			this.url = url;
			this.iv = iv;
		}

		@Override
		public void run() {
			iv.setImageBitmap(HttpUtils.returnBitMap(url));
		}
	}

}
